# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=nosqlmap
pkgver=300.54d3fdb
pkgrel=1
groups=('blackarch' 'blackarch-webapp' 'blackarch-exploitation')
pkgdesc='Automated Mongo database and NoSQL web application exploitation tool'
arch=('any')
url='https://github.com/tcstool/NoSQLMap'
license=('GPL3')
depends=('python2' 'python2-pymongo' 'python2-httplib2' 'python2-pbkdf2'
         'python2-ipcalc' 'python2-couchdb' 'python2-requests' 'python2-six'
         'mongodb')
makedepends=('git' 'python2-setuptools')
source=("$pkgname::git+https://github.com/tcstool/NoSQLMap.git"
        'nosqlmap.py.patch')
sha512sums=('SKIP'
            '908c971bd7cdb3643847d1ead8ff77c6e8ced1673854167028b2993637d48643a0398185978c36a4df57f9f83a810c7a3f5bda19238f7fdc4cb2979878a6d699')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

prepare() {
  cd $pkgname

  #sed -i '2i\#-*- coding: utf-8 -*-' nosqlmap.py

  #patch -Np0 -i ../nosqlmap.py.patch
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md TODO
  install -Dm 644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"

  rm README.md TODO COPYING

  cp -a * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname/
exec python2 $pkgname.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

